﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Yipusoft.Account.BLL;
using Yipusoft.Account.Model;

public partial class BasicBase_FireProject_UCDepartment : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Yipusoft.Account.BLL.User.HasPermission(Page.User.Identity.Name, "201301"))//总队级
            {
                DepartmentList.Visible = true;
                UnitList.Visible = true;
                DepartmentList.DataSource = Yipusoft.Account.BLL.Department.GetList(" (SUBSTRING(DepartmentID, 5, 3) = '000') ");
                DepartmentList.DataBind();
                DepartmentListBind();
            }
            else if (Yipusoft.Account.BLL.User.HasPermission(Page.User.Identity.Name, "201302"))//支队级
            {
                DepartmentList.Visible = true;
                UnitList.Visible = true;
                string Departmentid = User.GetUser(Page.User.Identity.Name).DepartmentID;
                List<DepartmentInfo> list = Yipusoft.Account.BLL.Department.GetList(" DepartmentID=('" + Departmentid.Substring(0, 4) + "000') or DepartmentID='1300000' ");
                DepartmentList.DataSource = list;
                DepartmentList.DataBind();
                DepartmentListBind();
            }
            else if (Yipusoft.Account.BLL.User.HasPermission(Page.User.Identity.Name, "201310"))
            {
                Unit.Visible = true;
                string Departmentid = User.GetUser(Page.User.Identity.Name).DepartmentID;
                string strWhere = "(departmentid like '" + Departmentid.Substring(0, 4) + "%'  and  SUBSTRING(DepartmentID, 5, 1)<>'0') or departmentid='" + Departmentid + "' or fullName like '%指挥中心%'  and   (DepartmentID LIKE '" + Departmentid.Substring(0, 4) + "%')  or fullName like '%司令%' and   (DepartmentID LIKE '" + Departmentid.Substring(0, 4) + "%') or fullName like '%警务%' and   (DepartmentID LIKE '" + Departmentid.Substring(0, 4) + "%') or fullName like '%警勤中队%' and   (DepartmentID LIKE '" + Departmentid.Substring(0, 4) + "%') or fullName like '%战训%' and   (DepartmentID LIKE '" + Departmentid.Substring(0, 4) + "%')";
                Unit.DataSource = Department.GetList(strWhere);
                Unit.DataBind();
            }
            else if (Yipusoft.Account.BLL.User.HasPermission(Page.User.Identity.Name, "201303"))//本单位级
            {
                lblUnit.Visible = true;
                string Departmentid = User.GetUser(Page.User.Identity.Name).DepartmentID;
                DepartmentInfo info = Department.GetDepartment(Departmentid);
                lblUnit.Text = info.FullName;
                lblDepartmentid.Text = Departmentid;
            }
        }
    }

    void DepartmentListBind()
    {
        string Departmentid = DepartmentList.SelectedValue;
        string strWhere = "(departmentid like '" + Departmentid.Substring(0, 4) + "%'  and  SUBSTRING(DepartmentID, 5, 1)<>'0')  or fullName like '%指挥中心%'  and   (DepartmentID LIKE '" + Departmentid.Substring(0, 4) + "%')  or fullName like '%司令%' and   (DepartmentID LIKE '" + Departmentid.Substring(0, 4) + "%') or fullName like '%警务%' and   (DepartmentID LIKE '" + Departmentid.Substring(0, 4) + "%') or fullName like '%警勤中队%' and   (DepartmentID LIKE '" + Departmentid.Substring(0, 4) + "%') or fullName like '%战训%' and   (DepartmentID LIKE '" + Departmentid.Substring(0, 4) + "%')";

        UnitList.DataSource = Department.GetList(strWhere);
        UnitList.DataBind();
    }

    public string GetDepartmentID()
    {
        string pp = "";
        if (Yipusoft.Account.BLL.User.HasPermission(Page.User.Identity.Name, "201301"))//总队级
        {
            pp = UnitList.SelectedValue;
        }
        else if (Yipusoft.Account.BLL.User.HasPermission(Page.User.Identity.Name, "201302"))//支队级
        {
            pp = UnitList.SelectedValue;
        }
        else if (Yipusoft.Account.BLL.User.HasPermission(Page.User.Identity.Name, "201310"))//中队级
        {
            pp = Unit.SelectedValue;
        }
        else if (Yipusoft.Account.BLL.User.HasPermission(Page.User.Identity.Name, "201303"))//本单位级
        {
            pp = lblDepartmentid.Text;
        }
        return pp;
    }

    public void setDepartmentID(string id)
    {
        if (Yipusoft.Account.BLL.User.HasPermission(Page.User.Identity.Name, "201501"))//总队级
        {
            DepartmentList.SelectedValue = id.Substring(0, 4) + "000";
            UnitList.SelectedValue = id;
        }
        else if (Yipusoft.Account.BLL.User.HasPermission(Page.User.Identity.Name, "201502"))//支队级
        {
            Unit.SelectedValue = id;
        }

    }

    protected void DepartmentList_TextChanged(object sender, EventArgs e)
    {
        DepartmentListBind();
    }
}
